<?php

namespace app\admin\middleware;


use app\common\lib\JwtUtil;
use think\Response;

class checkLogin
{
    protected $noCheck = [
        '/admin/Login/login',
        '/admin/login/login',
        '/admin/login/index',
        '/admin/Login/index',
        '/admin/Index/login',
        '/admin/Index/index',
        '/admin/index/index',
        '/admin/index/home',
        '/admin/Robot/index',
        '/admin/robot/index',
        '/admin/Robot/friend',
        '/admin/robot/friend',
        '/admin/Robot/group',
        '/admin/robot/group',
        '/admin',

    ];
    public function handle($request,\Closure $next)
    {

        $url = $_SERVER['PATH_INFO'];
        if(!$url) $url = $_SERVER['REQUEST_URI'];
        $url = trim($url,'?');
        if(!in_array($url,$this->noCheck)){
            $token = $request->header('token');
            if(!$token || $token ==='null'){
                return echoJson(errorJson('请重新登录',401));
            }
            $params = deToken($token);
            $request['admin_id'] = $params->uid;
        }
        return $next($request);
    }

}